import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error



# data = pd.read_csv("asd.csv")
#
# x=data[['Price','Brand','Features']]
#
# y=data['Sales']
#
# X_train,X_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=42)
#
# model = LinearRegression()
#
# model.fit(X_train,y_train)
# y_pred=model.predict(X_test)
#
# print(y_pred)
#
#
# mse=mean_squared_error(y_test,y_pred)
#
# print("mean squared error",mse)

import pickle

# train the model




x=[[1,2],[3,4],[5,6]]
y=[3,7,11]
x_train,x_test,y_train,y_test=train_test_split(x, y, test_size=0.2, random_state=42)
#数据
print(x_train)
#测试数据
print(x_test)
print('------------------------------------------')
#值
print(y_train)
#测试值
print(y_test)

#训练
model = LinearRegression()
model.fit(x,y)

# # save the model
# with open('my_model.pkl', 'wb') as f:
#     pickle.dump(model, f)
#
#
# import pickle
#
# # load the saved model
# with open('my_model.pkl', 'rb') as f:
#     model = pickle.load(f)
#
# # predict using the loaded model
# model.predict(X)


# import pickle
#
# # load the saved model
# with open('my_model.pkl', 'rb') as f:
#     model = pickle.load(f)
#
# # continue training the model
# model.fit(X_train, y_train)
#
# # save the updated model
# with open('my_updated_model.pkl', 'wb') as f:
#     pickle.dump(model, f)
#


re = model.predict([[10,30]])

#输入测试值和训练值
rr=mean_squared_error([32],re)
print(re)
print(rr)